package com.thinkgem.jeesite.modules.cms.web;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.modules.cms.entity.TaskOperation;
import com.thinkgem.jeesite.modules.cms.service.TaskOperationService;
@Controller
@RequestMapping(value = "${adminPath}/cms/taskGdp")
public class TaskGdpController  extends BaseController {
	@Autowired
	private TaskOperationService taskOperationService;
	
	@RequestMapping(value ={"list"})
	public String list(TaskOperation taskOperation, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<TaskOperation> page = taskOperationService.findPage(new Page<TaskOperation>(request, response), taskOperation); 
		model.addAttribute("page", page);
		return "modules/cms/taskGdp";//"redirect:"+Global.getAdminPath()+"/cms/taskinput/?repage";//
	}
	
	@RequestMapping(value ={""})
	public String list2(TaskOperation taskOperation, HttpServletRequest request, HttpServletResponse response, Model model) {
		return "modules/cms/taskGdp";//"redirect:"+Global.getAdminPath()+"/cms/taskinput/?repage";//
	}
	
	@RequiresPermissions("cms:taskGdp:view")
	@RequestMapping(value = "form")
	public String form(TaskOperation taskOperation, Model model) {
		model.addAttribute("taskOperation", taskOperationService.get(taskOperation.getId()));
		return "modules/cms/taskGdpForm";
	}
	
	@RequiresPermissions("cms:taskGdp:edit")
	@RequestMapping(value = "save")
	public String save(TaskOperation taskOperation, Model model, RedirectAttributes redirectAttributes) {
//		if (!beanValidator(model, taskOperation)){
//			return form(taskOperation, model);
//		}
		TaskOperation t = taskOperationService.get(taskOperation.getId());
		t.setA(taskOperation.getA());
		t.setB(taskOperation.getB());
		t.setC(taskOperation.getC());
		t.setD(taskOperation.getD());
		t.setE(taskOperation.getE());
		t.setF(taskOperation.getF());
		t.setG(taskOperation.getG());
		t.setH(taskOperation.getH());
		taskOperationService.save(t);
		addMessage(redirectAttributes, "保存信息成功");
		//return "redirect:"+Global.getAdminPath()+"/cms/taskGdp/?repage";
		return "forward:"+Global.getAdminPath()+"/cms/taskGdp/list";
	}
}
